package com.jxs.android.weiget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jxs.android.weiget.SpinnerButton.ViewCreatedListener;
import com.telecom.weixi.R;

public class LaucherTopBar extends LinearLayout implements OnClickListener {

	private View topLayout;
	private LayoutInflater mInflater;
	private Button returnBtn;
	private SpinnerButton logicBtn;
	private TextView titleTextView;
	private ReturnBtnListern topBarReturnListern;

	public LaucherTopBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
		this.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
	}

	private void init(Context context) {
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		topLayout = (View) mInflater.inflate(R.layout.bu_lacher_top_bar, null);
		returnBtn = (Button) topLayout.findViewById(R.id.top_bar_return);
		logicBtn = (SpinnerButton) topLayout.findViewById(R.id.top_bar_btn);
		titleTextView = (TextView) topLayout.findViewById(R.id.top_bar_title);

		returnBtn.setOnClickListener(this);
		addView(topLayout);
	}

	@Override
	public void onClick(View v) {
		if (v.getId() == returnBtn.getId()) {
			if (null != topBarReturnListern) {
				topBarReturnListern.onClickReturn();
			}
		}
	}

	public void setTopBarReturnListern(ReturnBtnListern topBarReturnListern) {
		this.topBarReturnListern = topBarReturnListern;
	}

	public void setResIdAndViewCreatedListener(int mResId, ViewCreatedListener mViewCreatedListener) {
		logicBtn.dismiss();
		logicBtn.setResIdAndViewCreatedListener(mResId, mViewCreatedListener);
	}

	public void dismisssWind() {
		logicBtn.dismiss();
	}

	public void hindAllBtn() {
		returnBtn.setVisibility(GONE);
		logicBtn.setVisibility(GONE);
	}

	public void hindAll() {
		hindAllBtn();
		titleTextView.setVisibility(GONE);
	}

	public void hindReturn() {
		returnBtn.setVisibility(GONE);
	}

	public void hindBtn() {
		logicBtn.setVisibility(GONE);
	}

	public void showBtn() {
		logicBtn.setVisibility(VISIBLE);
	}

	public void hindSelf() {
		this.setVisibility(GONE);
	}

	public void setTitle(CharSequence text) {
		titleTextView.setText(text);
	}

	public void setTitle(int textId) {
		titleTextView.setText(textId);
	}

	public void setLogicBtnText(CharSequence text) {
		logicBtn.setText(text);
	}

	public void setLogicBtnText(int textId) {
		logicBtn.setText(textId);
	}

	static public interface ReturnBtnListern {
		public void onClickReturn();

	}

}
